<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\facade\Session;
use app\index\model\Money;

class Rawal extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        Session::set('userid',1);
        $id= Session::get('userid');
        $data=Money::where('userid',$id)->find();

        return $this->fetch('wallet',['data'=>$data]);
    }
    public function recharge(Request $request){

        return $this->fetch('recharge');
    }
    public function recharges(Request $request){
        $id= Session::get('userid');
        $credit2=$request->param('credit2');
        $data=Money::where('userid',$id)->find();
        if(empty($data)){
            $money=new Money();
            $money->userid=$id;
            $money->number=$credit2;
            $money->save();
        }else{
            $money= Money::get($id);
            $money->userid=$id;
            $money->number=$data->number+$credit2;
            $money->save();
        }

        $type=$request->param('pay_type');
//        var_dump($type);die;
        if($type=='1'){
            $id= Session::get('userid');

            return $this->fetch('recharge1');
        }
        if($type=='2'){
            return $this->fetch('recharge2');
        }
    }
    public function water(Request $request){
        return $this->fetch('water');
    }
    public function withdawn(Request $request){
        return $this->fetch('withdawn');
    }
    public function do_withdawn(Request $request){
        $id= Session::get('userid');
        $number=$request->param('number');
        $data=Money::where('userid',$id)->find();
        $money= Money::get($id);
        $money->userid=$id;
        $money->number=$data->number-$number;
        $money->save();
        return json(['msg'=>'提现成功']);
    }
    public function shiname(){
        return $this->fetch();
    }
}
